/**
 * Project Name:九色鹿
 * File Name:SmsServiceContext.java
 * Package Name:com.fxp.project.jiuselu.sms.context
 * Date:2020年04月01日 23:04
 * Copyright (c) 2020, Jason.Wang All Rights Reserved.
 */
package com.fxp.project.jiuselu.sms.context;

import com.fxp.project.jiuselu.commons.exceptions.JiuLuException;
import com.fxp.project.jiuselu.sms.enums.SmsEnumType;
import com.fxp.project.sms.chuanglan.service.ISmsService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * ClassName:SmsServiceContext<br/>
 * Function: 发送短信的调用类<br/>
 * Date:2020年04月01日 23:04<br/>
 *
 * @author Jason.Wang
 * @version 1.0.0.0
 * @see
 * @since JDK1.8
 */
@Log4j2
@Component
public class SmsServiceContext {

    /**
     * 注入ISmsService子类的service,key为子类service的key
     */
    @Autowired
    private Map<String, ISmsService> smsServiceMap;

    /**
     * sendSms: 统一发送短息的接口<br/>
     *
     * @param type
     * @param mobile
     * @param message
     * @return
     * @throws JiuLuException
     * @author Jason.Wang
     * @createTime 2020/4/1 22:07
     */
    public boolean sendSms(Integer type, String mobile, String message) throws JiuLuException {
        String serviceKey = SmsEnumType.getEnumByType(type).getService();
        //获取对应的活动service
        ISmsService smsService = smsServiceMap.get(serviceKey);
        // 调用发送短信的方法
        return smsService.sendSms(mobile, message);
    }
}
